package com.dashunwms_aohe.job;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.dashunwms_aohe.bean.Qf_BillType;
import com.dashunwms_aohe.bean.ZxyUploadbillDS;
import com.dashunwms_aohe.dao.ZxyUploadbillDSDao;
import com.dashunwms_aohe.http.res.UploadBillRes;
import com.dashunwms_aohe.service.UploadBillService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class UploadBIllJob {

    @Resource
    private ZxyUploadbillDSDao zxyUploadbillDSDao;
    @Resource
    private UploadBillService uploadBillService;

    @Scheduled(fixedDelay = 600000)
    public void uploadBuyOrderBill() {
        log.error(DateUtil.now());
        List<ZxyUploadbillDS> uploadBillByBilltype = zxyUploadbillDSDao.getUploadBillByBilltype(Qf_BillType.QF_Buy);
        for (ZxyUploadbillDS uploadBill : uploadBillByBilltype) {
            UploadBillRes uploadBillRes = uploadBillService.uploadBuyBillToDS(uploadBill.getBillcode());
            log.info("采购上传定时器返回数据" + JSON.toJSONString(uploadBillRes));
        }
    }

    @Scheduled(fixedDelay = 605000)
    public void uploadSaleBill() {
        List<ZxyUploadbillDS> uploadBillByBilltype = zxyUploadbillDSDao.getUploadBillByBilltype(Qf_BillType.QF_Sale);
        for (ZxyUploadbillDS uploadBill : uploadBillByBilltype) {
            UploadBillRes uploadBillRes = uploadBillService.uploadSaleBillToDS(uploadBill.getBillcode());
            log.info("销售上传定时器返回数据" + JSON.toJSONString(uploadBillRes));
        }
    }

    @Scheduled(fixedDelay = 607000)
    public void uploadBuyBackBill() {
        List<ZxyUploadbillDS> uploadBillByBilltype = zxyUploadbillDSDao.getUploadBillByBilltype(Qf_BillType.QF_BuyBack);
        for (ZxyUploadbillDS uploadBill : uploadBillByBilltype) {
            UploadBillRes uploadBillRes = uploadBillService.uploadBuyBackBillToDS(uploadBill.getBillcode());
            log.info("采购退货上传定时器返回数据" + JSON.toJSONString(uploadBillRes));
        }
    }

    @Scheduled(fixedDelay = 608000)
    public void uploadSaleBackBill() {
        List<ZxyUploadbillDS> uploadBillByBilltype = zxyUploadbillDSDao.getUploadBillByBilltype(Qf_BillType.QF_SaleBack);
        for (ZxyUploadbillDS uploadBill : uploadBillByBilltype) {
            UploadBillRes uploadBillRes = uploadBillService.uploadSaleBackBillToDS(uploadBill.getBillcode());
            log.info("销售退货上传定时器返回数据" + JSON.toJSONString(uploadBillRes));
        }
    }

}
